package blocksim.hash;

import org.bdwyer.fingerprint.RabinFingerprintLongWindowed;
import org.bdwyer.polynomial.Polynomial;

/**
 * Adapter for the Rabin Fingerprint hash strategy
 * 
 * @author marcus
 */
public class RabinHashStrategy implements HashStrategy {

  public static final String STRATEGY_ID = "Rabin";

  private RabinFingerprintLongWindowed rabin;

  public RabinHashStrategy(int windowSize, int polynomialDegree) {
    rabin = new RabinFingerprintLongWindowed(Polynomial.createIrreducible(polynomialDegree),
        windowSize);
  }

  @Override
  public void pushBytes(byte[] bytes) {
    rabin.pushBytes(bytes);
  }

  @Override
  public void pushBytes(byte[] bytes, int offset, int len) {
    rabin.pushBytes(bytes, offset, len);
  }

  @Override
  public byte[] hash() {
    return rabin.getFingerprint().toBigInteger().toByteArray();
  }

  @Override
  public String getName() {
    return STRATEGY_ID;
  }

}
